package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.UserDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-10-13
 */
public interface UserMapper extends BaseMapper<UserDO> {

    /**
     * 查询用户列表
     *
     * @return
     * @description 2048 该角色的用户无需同步（新系统里没有自营司机用户了）
     */

    @Select("select tu.User_ID as userId, tu.User_Account as userAccount, tu.User_Password as userPassword, tu.User_CompanyID as userCompanyid, tu.User_RoleID as userRoleid, tu.User_Name as userName " +
            ", LEFT(tu.User_Nickname,50) as userNickname, tu.User_Portrait as userPortrait, tu.User_Language as userLanguage " +
            ", tu.User_Gender as userGender, tu.User_Birthday as userBirthday, tu.User_Phone as userPhone, tu.User_Dept as userDept, tu.User_Duty as userDuty " +
            ", tu.User_InsertTime as userInserttime, tu.User_Invalid as userInvalid, tu.User_UpdateTime as userUpdatetime, tu.User_SignInTime as userSignintime " +
            ", tu.User_Comments suserComments, opt_status as optStatus, tu.User_Type as userType, tu.User_OpenId as userOpenid, tu.User_System as userSystem, tu.User_FirstChangePWD as userFirstchangepwd " +
            ", tu.User_CloseTime as userClosetime, tu.User_AssociatedUserID as userAssociateduserid, tu.User_isDomain as userIsdomain from TMS_User tu " +
            "where tu.User_CompanyID > 0 ")
    @DataScope(column = "User_CompanyID", alias = "tu")
    List<UserDO> list();

    @Select("SELECT User_ID FROM TMS_User WHERE User_InsertTime >= #{startTime} and User_InsertTime <= #{endTime} ")
    List<Long> getByTime(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT User_ID FROM TMS_User WHERE User_CompanyID = #{tenantId} and User_InsertTime >= #{startTime} and User_InsertTime <= #{endTime} ")
    List<Long> getByTenantIdTime(@Param("tenantId") Long tenantId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
